#pragma once

#define NUM_BACKGROUND_BLOCKS	20
#define SPEED_BACKGROUND_BLOCKS	0.2f

#define TO_SCREENX(x)	( (float(x)/640.0f) * Iw2DGetSurfaceWidth() )
#define TO_SCREENY(y)	( (float(y)/960.0f) * Iw2DGetSurfaceHeight() )

// Forward declarations.
namespace UI
{
	class Menu;
}
class Game;
class CIw2DFont;
class CIwSoundSpec;
class CIwSoundInst;

class Engine
{
	static Engine* m_Singleton;
public:
	static Engine* SetSingletonPtr( Engine* a_Engine )	{ m_Singleton = a_Engine; return m_Singleton; }
	static Engine* GetSingletonPtr()	{ return m_Singleton; }

	enum T_ENGINESTATE
	{
		MAINMENU = 0,
		GAME,
		EXIT
	};

	Engine();
	~Engine();

	void Run();

	T_ENGINESTATE GetEngineState();
	void SwitchEngineState( T_ENGINESTATE a_State );

	void UpdateMusicVolume();

	int GetCurrentHighscore();
	void SetHighscore( int a_Score );

	float m_MaxMusicVolume;
	float m_MinMusicVolume;
	float m_MusicVolume;
private:
	T_ENGINESTATE m_EngineState;

	void Init();
	void Loop();
	void Terminate();

	void DrawDebugInfo();

	void ConstructMainMenu();

	Game* m_Game;	// Main game object.
	UI::Menu* m_Menu;	// Main menu object.

	CIw2DFont* m_Font;
	CIw2DImage* m_Background;

	CIwSoundSpec* m_MusicSpec;	
	CIwSoundInst* m_MusicInstance;

	int m_BackgroundBlocksTypes[NUM_BACKGROUND_BLOCKS];
	CIwSVec2 m_BackgroundBlocksPositions[NUM_BACKGROUND_BLOCKS];
	CIwSVec2 m_BackgroundBlocksSize;

	CIw2DImage* m_LoadingImage;

	int m_CurrentHighscore;
};